// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.iso.IsoMovingObject;
import zombie.iso.objects.IsoWindow;
import zombie.network.packets.INetworkPacket;

public class HitInfo implements INetworkPacket {
    public MovingObject object;
    public NetObject window;
    public float x;
    public float y;
    public float z;
    public float dot;
    public float distSq;
    public int chance = 0;

    public HitInfo() {
        this.object = new MovingObject();
        this.window = new NetObject();
    }

    public HitInfo init(IsoMovingObject obj, float _dot, float _distSq, float _x, float _y, float _z) {
        this.object = new MovingObject();
        this.window = new NetObject();
        this.object.setMovingObject(obj);
        this.window.setObject(null);
        this.x = _x;
        this.y = _y;
        this.z = _z;
        this.dot = _dot;
        this.distSq = _distSq;
        return this;
    }

    public HitInfo init(IsoWindow obj, float _dot, float _distSq) {
        this.object = new MovingObject();
        this.window = new NetObject();
        this.object.setMovingObject(null);
        this.window.setObject(obj);
        this.z = obj.getZ();
        this.dot = _dot;
        this.distSq = _distSq;
        return this;
    }

    public IsoMovingObject getObject() {
        return this.object.getMovingObject();
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.object.parse(b, connection);
        this.window.parse(b, connection);
        this.x = b.getFloat();
        this.y = b.getFloat();
        this.z = b.getFloat();
        this.dot = b.getFloat();
        this.distSq = b.getFloat();
        this.chance = b.getInt();
    }

    @Override
    public void write(ByteBufferWriter b) {
        this.object.write(b);
        this.window.write(b);
        b.putFloat(this.x);
        b.putFloat(this.y);
        b.putFloat(this.z);
        b.putFloat(this.dot);
        b.putFloat(this.distSq);
        b.putInt(this.chance);
    }

    @Override
    public int getPacketSizeBytes() {
        return 24 + this.object.getPacketSizeBytes() + this.window.getPacketSizeBytes();
    }

    @Override
    public String getDescription() {
        return "\n\tHitInfo [ x="
            + this.x
            + " y="
            + this.y
            + " z="
            + this.z
            + " dot="
            + this.dot
            + " distSq="
            + this.distSq
            + " chance="
            + this.chance
            + "\n\t Object: "
            + this.object.getDescription()
            + "\n\t Window: "
            + this.window.getDescription()
            + " ]";
    }
}
